<?php
declare (strict_types = 1);
namespace app\admin\validate\finance;

use think\Validate;

/**
 * 充值配置验证
 */
class Recharge extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'id'           => 'require',
        'price'        => 'gt:0',
        'balance'      => 'gt:0',
        'give_balance' => 'egt:0',
        'product_id'   => 'requireIf:is_ios,1|unique:recharge_config',

    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'price'                => '购买价格必须大于0',
        'balance'              => '获得余额必须大于0',
        'give_balance'         => '赠送余额必须大于等于0',
        'product_id.requireIf' => '必须填写内购商品ID',
        'product_id.unique'    => '已存在相同的内购产品ID，不可重复添加',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'create' => ['price', 'balance', 'give_balance', 'product_id'],
        'edit'   => ['id', 'price', 'balance', 'give_balance', 'product_id'],
    ];
}
